// import { reactive } from "../../../HBuilderX.3.8.4.20230531/HBuilderX/plugins/hbuilderx-language-services/builtin-dts/common/vue2And3";
import { reactive } from "vue";
export function custmStyle() {
   const custmStyle = reactive({
	  backgroundColor: ' #ffc300'
   })
   return custmStyle
}

/**
 * @param {array} formList 表单数组 
 */  
export function formatFormList(formList){
  return formList.map(item => {
    let {fieldType,value,fieldOptions} = item
    value = value||""
    fieldOptions = fieldOptions?JSON.parse(item.fieldOptions):[]
    switch (fieldType) {
      case 2:
        if (value) {
          let temp = value.split(",")
          let str = ""
          if(fieldOptions.length){
            temp.forEach(item => {
              let name = fieldOptions.find(item2 => item2.id == item).name
              str = str?`${str},${name}`:name
            })
          }else{
            str = temp
          }
          value = str
        }
      case 3:
        const arr = value.split(",")
        if (value && arr.length > 1) {
          value = arr[0] + ' - ' + arr[1]
        }
        break
      case 4:
        value&&(value = value.split(","))
        break
      case 6:
        if(value&&fieldOptions.length&&typeof fieldOptions[0] == 'object'){
            value = fieldOptions.find(item=>item.id==value).name
        }
        break
      case 7:
        value&&(item.value = JSON.parse(value).address)
        break
    }
    return {
      ...item,
      value
    }
  })
}

/**
 * @param {object} innerAudioContext 音频对象
 * @param {object} options 可选对象里面包含音频对象的监听函数
 */ 
export function clearAudioFn(innerAudioContext,options={}){
	const {onPlay,onPause,onStop,onEnded} = options
	innerAudioContext.stop()
	innerAudioContext.offPlay(onPlay)
	innerAudioContext.offPause(onPause)
	innerAudioContext.offStop(onStop)
	innerAudioContext.offPlay(onEnded)
	
}